# -*- coding: utf-8 -*-
# author: AZJ
# date: 2024/11/7
# 假如命运扼住了你的咽喉，你就去挠她的咯吱窝
import pymysql
conn = pymysql.connect(
    host='localhost',
    port=3306,
    user='root',
    passwd='root123',
    db='test',
    charset='utf8'
)
column = ["用户名", "年龄", "性别", "身高"]
print("请输入数据：")

value = ""
for i in range(10):
    # print(f"{' | '}".join(column))
    username = input("用户名>>")
    age = input("年龄>>")
    sex = input("性别>>")
    high = input("身高>>")
    if i == 9:
        value = value + f"('{username}',{age},'{sex}',{high})"
        continue
    value = value + f"('{username}',{age},'{sex}',{high}),"
    print(value)
# value = "('001',18,'nv',170),('002',18,'nan',180),('003',17,'nv',150),('004',17,'nan',170),('005',19,'nv',175),('006',19,'nan',179),('007',20,'nan',180),('008',22,'nv',180),('009',23,'nv',178),('010',25,'nv',170)"
try:
    with conn.cursor() as cursor:
        sql = f"INSERT INTO person VALUES {value}"
        cursor.execute(sql)
        conn.commit()
except Exception as e:
    print("数据库操作异常:\n", e)
    conn.rollback()
finally:
    conn.close()
